﻿using dz.u9.jky.schema.Common;
using dz.util.core;
using Newtonsoft.Json.Linq;

namespace dz.u9.webapi
{
    public class MessageConvert
    {
        public static U9CResult Convert(string data)
        {
            U9CResult rtn = new U9CResult();

            JObject obj = JObject.Parse(data);

            //"IsSucess":true,"U9CVersion":null,"OtherID":"aaaa","ID":1002410160000110,"Code":"（记）-2023-10-0025","ErrorMsg":null}

            if (obj["Data"] is JArray dataArray && dataArray.Count > 0)
            {
                JObject firstItem = (JObject)dataArray[0];

                rtn.IsSuccess = firstItem["IsSucess"].Value<bool>();
                rtn.Id = firstItem["ID"].Value<long>();
                rtn.DocNo = firstItem["Code"].Value<string>();

                if (!rtn.IsSuccess)
                    rtn.Message = firstItem["ErrorMsg"].Value<string>();
            }
            return rtn;
        }

        public static string Convert1(string data)
        {
            return data;
        }

        public static U9CResult ConvertFromInnerApi(string data)
        {
            return JsonUtil.Deserialize<U9CResult>(data);
        }
    }
}
